package com.qf.blog.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

// 项目启动的时候给上下文域对象中放到了模板引擎对象
@WebListener
public class SpringInitListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {

        // 1.初始化spring工厂
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");

        // 2.把工厂放到上下文
        sce.getServletContext().setAttribute("spring",context);

    }
}